import { floatToFixed2 } from '@/utils'
import { ProcessStatus } from './constants'

// 格式化金额【分转元】
// @ts-ignore
export const fenToYuanFormat = (_, __, cellValue: any, ___) => {
  return `￥${floatToFixed2(cellValue)}`
}

export const formatTimeString = (timeString: string, defaultValue = '--:--'): string | null => {
  timeString = timeString?.toString().trim() || ''
  if (timeString.includes(':')) return timeString
  if (!/^\d{4}$/.test(timeString)) return null
  const hours = parseInt(timeString.slice(0, 2))
  const minutes = parseInt(timeString.slice(2, 4))
  if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
    return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`
  }
  return defaultValue
}


export const formatProcessStatus = (status: number): string => {
  return ProcessStatus.find(item => item.value === status)?.label || '未知'
}